﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.Module.Entities;
using Infrastructure.DataObjects;
using Framework;
using Framework.Repositories;
using Framework.Services;
using Framework.UnitOfWork;
using Microsoft.Practices.Unity;
using Domain.Module.Roles;
using Domain.Context;
using Framework.Infrastructure;

namespace Application.AppServices.CommentManagement
{
    class CommentManagementService : ApplicationService, ICommentManagementService
    {

        public CommentManagementService(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {

        }
        #region IRepositories
        IRepository<User> UserRepository
        {
            get
            {
                return GetRepository<User>();
            }
        }
        IRepository<MBlog> MBlogRepository
        {
            get
            {
                return GetRepository<MBlog>();
            }
        }

        IRepository<Comment> CommentRepository
        {
            get
            {
                return GetRepository<Comment>();
            }
        }
        #endregion

        #region ICommentManagementService Members

        public void PublishMBlogComment(Guid publisherID, Guid mblogID, CommentObject commentObject)
        {
            var user = UserRepository.GetByKey(publisherID);
            var mblog = MBlogRepository.GetByKey(mblogID);
           var commentContext = new CommentContext(user.ActAs<ICommentator>(), mblog.ActAs<IBeCommented>(), commentObject);
           commentContext.Interactive();
           UnitOfWork.Commit();
        }

        public void PublishUserComment(Guid publisherID, Guid userID, CommentObject commentObject)
        {
            var publisher = UserRepository.GetByKey(publisherID);
            var user = UserRepository.GetByKey(userID);
            var commentContext = new CommentContext(user.ActAs<ICommentator>(), user.ActAs<IBeCommented>(), commentObject);
            commentContext.Interactive();
            UnitOfWork.Commit();
        }


        // commnet context
        protected void DoComment(ICommentator user, IBeCommented beCommented, CommentObject commentObj)
        {

        }

        #endregion
    }
}
